import React, { useEffect } from 'react';
import { Upload, Card, Button } from 'antd';

const data = [
    { id: 1, name: "办公管理", pid: 0 },
    { id: 2, name: "请假申请", pid: 1 },
    { id: 3, name: "出差申请", pid: 1 },
    { id: 4, name: "请假记录", pid: 2 },
    { id: 5, name: "系统设置", pid: 0 },
    { id: 6, name: "权限管理", pid: 5 },
    { id: 7, name: "用户角色", pid: 6 },
    { id: 8, name: "菜单设置", pid: 6 },
];

const UploadPage = () => {

    useEffect(() => {
        // 现将数据的主键id转化为新数组的下标
        const newData = [];

        data.forEach((item) => {
            newData[item.id] = item;
        });
        // console.log('data', data);
        // console.log('newData', newData);
        const treeData = [];
        data.forEach((item) => {
            const parentNode = newData[item.pid];
            console.log('parent',parentNode)
            if (parentNode) {
                if (parentNode.subList || (parentNode.subList = [])) parentNode.subList.push(item);
            } else {
                treeData.push(item);
            }
        });

        console.log('tree', treeData);
    });

    return (
        <Card>
            <Upload
                action='https://www.mocky.io/v2/5cc8019d300000980a055e76'
            >
                <Button>上传文件</Button>
            </Upload>
        </Card >
    )
}

export default UploadPage;